import { createStore } from 'vuex'
import appAxios from '../appAxios'
export interface stateType{
  list:listType[],
  token:string,
  user:string,
  pwd:string,
  id:string
}
export interface listType{
  user:string,
  pwd:string,
  id:string,
  token:string
}
export default createStore<stateType>({
  // 使用VueX实现登录动作
  state: {
    list:[],
    token:'',
    user:'',
    pwd:'',
    id:''
  },
  getters: {
  },
  mutations: {
    setLoginList:(state,action)=>{
      console.log(action)
      state.list=action
    },
    getToken:(state,action)=>{
      state.id=action.id
      state.user=action.user
      state.pwd=action.pwd
      state.token=action.token
    },
    getTokenqing:(state)=>{
      state.id=''
      state.user=''
      state.pwd=''
      state.token=''
    }
  },
  actions: {
    // 二次封装axios
    async getLoginListAxios({commit}){
      const resp=await appAxios.get('/api/login')
      commit('setLoginList',resp.data)
    }
  },
  modules: {
  }
})
